package net.zdreamer.shunyi.ui.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.ui.FaBuActivity;

public class BangHuiFragment extends Fragment implements RadioGroup.OnCheckedChangeListener, View.OnClickListener {
    private RelativeLayout titleitem;
    private TextView titlecontent;
    private ImageView title_right;
    private RadioGroup radio_group;
    private RadioButton banghui_news, banghui_guangchang, banghui_taojin;
    private Intent intent;
    private boolean isshow = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_banghui, container, false);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        addFragment(new BanghuiNewsFragment());
    }

    @Override
    public void onStart() {
        super.onStart();
        titleitem = (RelativeLayout) getView().findViewById(R.id.title_item);
        titlecontent = (TextView) getView().findViewById(R.id.title_content);

        title_right = (ImageView) getView().findViewById(R.id.right_image);
        titleitem.setBackgroundResource(R.drawable.banghuibiaoti);


        titlecontent.setText("顺义帮");
        titlecontent.setTextColor(getResources().getColor(R.color.bule));
        title_right.setImageResource(R.drawable.selector_camera);
         title_right.setVisibility(View.INVISIBLE);
        title_right.setOnClickListener(this);
        radio_group = (RadioGroup) getView().findViewById(R.id.fragmentgroup);
        banghui_news = (RadioButton) getView().findViewById(R.id.banghui_news);
        banghui_guangchang = (RadioButton) getView().findViewById(R.id.banghui_guangchang);
        banghui_taojin = (RadioButton) getView().findViewById(R.id.banghui_taojin);
        radio_group.setOnCheckedChangeListener(this);

    }

    public void addFragment(Fragment fragment) {
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();

        ft.replace(R.id.newfragment, fragment);
        ft.commit();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.banghui_news:
                addFragment(new BanghuiNewsFragment());
                   title_right.setVisibility(View.INVISIBLE);
                break;
            case R.id.banghui_guangchang:
                addFragment(new BangHuiGuangChangFragment());
                   title_right.setVisibility(View.VISIBLE);
                break;
            case R.id.banghui_taojin:
                addFragment(new BangHuiTaoJinFragment());
                  title_right.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
        }
//
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.right_image:
                intent = new Intent(getActivity(), FaBuActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
